package com.chinamobile.iot.mqtt.interception;

import com.chinamobile.iot.mqtt.spi.model.StoredMessage;

/**
 * Created by szl on 2017/7/31.
 */
public interface MessageHandler {

    boolean init();

    void destroy();

    boolean onConnecting(final String clientId, final String mqttId);

    void onConnected(final String clientId, final String mqttId, boolean cleanSession);

    void onClientDisconnected(final String clientId, final String mqttId, boolean cleanSession);

    /**
     * when receive publish message， the broker will call this method to rout the message to the subscriber
     * @param clientId if null, mean this message is send from other broker, otherwise mean this message is send by a client under this broker
     * @param mqttId mqttId
     * @param msg the message
     * @param filter the subscription filter
     * @param subCount the count of client that the msg math the filter
     *
     */
    void onTopicPublished(final String clientId, final String mqttId, StoredMessage msg, String filter, int subCount);

    void onTopicSubscribed(final String clientId, final String mqttId, final String topicFilter, final int qos, boolean cleanSession, int oldQos);

    void onTopicUnsubscribed(final String topic, final int qos, final String clientId, boolean cleanSession);

    void onMessageAcknowledged(final String clientId, final String mqttId, final int messageId);

    void onRouteMessageToClient(String clientId, String mqttId, String topic);

}
